import {defineStore} from 'pinia'
import { ref } from 'vue'

export const useUserStore=defineStore('user',()=>{
   // 定义状态
      const token = ref(uni.getStorageSync('token') || '');
      const userinfo = ref(JSON.parse(uni.getStorageSync('userinfo') || '{}'));
  //定义方法
      const saveUserInfoToStorage = () => {
              uni.setStorageSync('userinfo', JSON.stringify(userinfo.value));
          };
      const updateUserInfo = (newUserinfo) => {
              userinfo.value = newUserinfo;
              saveUserInfoToStorage();
          };
      const updateToken = (newToken) => {
              token.value = newToken;
              saveTokenToStorage();
          };
      
      const saveTokenToStorage = () => {
              uni.setStorageSync('token', token.value);
          };
 return{
   token,
   userinfo
 }
})